package com.zl.study.mybatis.demo;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

public class MyBatisUtils {
  private MyBatisUtils() {}


  public static SqlSessionFactory getSqlSessionFactory() throws IOException {
    String resource = "resources/mybatis/mybatis-config.xml";

    // 从配置文件中创建SqlSessionFactory
    InputStream is = Resources.getResourceAsStream(resource);
    SqlSessionFactory ssf = new SqlSessionFactoryBuilder().build(is);
    return ssf;
  }
}
